<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* three.js (https://github.com/mrdoob/three.js)
* GLTFLoader (https://github.com/johh/three-gltf-loader)
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_planeModel"></title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style>
        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            width: 100%;
            position: relative;
        }

        #map {
            width: 100%;
            height: 100%;
        }

    </style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
<script type="text/javascript" include="three,GLTFLoader" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script>

    var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
       " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

    var host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-china/rest/maps/ChinaDark";

    var map, threeLayer,
        position = [104.0688174135384, 30.548051075500908];

    map = new mapboxgl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
                    "tileSize": 256,
                },
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
                "minzoom": 0,
                "maxzoom": 22
            }]
        },
        center: [104.0693966828, 30.5760411152],
        zoom: 13.23,
        bearing: 0.8568,
        pitch: 60,

    });
    map.addControl(new mapboxgl.NavigationControl(), 'top-left');

    loaderModels();


    function loaderModels() {
        var loader = new THREE.GLTFLoader();
        //加载gltf格式数据
        loader.load('./js/airplane/airplane.glb', function (gltf) {
            var scene = gltf.scene;
            scene.rotation.x = -Math.PI / 2;
            scene.rotation.y = Math.PI / 2;
            scene.scale.multiplyScalar(150);

            addThreeLayer(scene);
        });
    }

    function addThreeLayer(meshes) {
        threeLayer = new mapboxgl.supermap.ThreeLayer('three');
        threeLayer.on("initialized", render);
        threeLayer.addTo(map);

        function render() {
            var renderer = threeLayer.getThreeRenderer(),
                scene = threeLayer.getScene(),
                camera = threeLayer.getCamera();

            this.light = new THREE.PointLight(0xaaaaaa, 0.5);
            this.light.position.copy(camera.position);
            scene.add(this.light);
            scene.add(new THREE.AmbientLight(0xffffff));
            threeLayer.setPosition(meshes, position);
            //设置飞行高度
            meshes.translateY(5000);
            scene.add(meshes);

            (function animate() {
                requestAnimationFrame(animate);
                meshes.position.y -= 60;
                var center = map.getCenter().toArray();
                center[1] += 0.00008;
                map.setCenter(center);
                renderer.render(scene, camera);
            })()
        }

        //均匀光照，与相机位置同步
        threeLayer.on("render", function () {
            threeLayer.light.position.copy(threeLayer.renderer.camera.position);
        });
    }

</script>
</body>
</html>